package com.ludomancy.archeologyrpg;

import java.awt.Graphics;
import java.awt.Point;
import java.awt.Rectangle;

import com.ludomancy.gamelib.Button;
import com.ludomancy.gamelib.DialogWidget;
import com.ludomancy.gamelib.GameCanvas;
import com.ludomancy.gamelib.Layout;
import com.ludomancy.gamelib.PictureWidget;
import com.ludomancy.gamelib.TextWidget;
import com.ludomancy.gamelib.Utils;
import com.ludomancy.gamelib.Widget;
import com.ludomancy.gamelib.Button.ButtonListener;

public class BriefingWidget extends DialogWidget implements ButtonListener
{
	public static final int DIALOG_WIDTH = 330;
	public static final int DIALOG_HEIGHT = 220;
	public static final int DIALOG_TEXT_HEIGHT = DIALOG_HEIGHT - 40;
	private DialogWidget.DialogListener listener;

	public BriefingWidget(Widget parent, String brief, String buttonLabel, DialogWidget.DialogListener listener)
	{
		super(parent, new Rectangle());
		this.listener = listener;
		// create the controls
		PictureWidget portrait = new PictureWidget(this, "intro.png", DIALOG_WIDTH-10);
		TextWidget text = new TextWidget(this, new Rectangle(0,0,DIALOG_WIDTH - 5, DIALOG_TEXT_HEIGHT - 25 - portrait.getHeight()), brief, ((GameTheme)getTheme()).tinyFont);
		Button ok = new Button(this, new Rectangle(5,0,DIALOG_WIDTH-10, 25),buttonLabel, this);
		
		// arrange the controls
		Widget[][] widgets = 
		{
			{portrait},
			{text},
		};
		Layout.doLayout(widgets, 5, 5, 5);
		
		Point center = Utils.getCenterInRect(new Point(DIALOG_WIDTH,DIALOG_HEIGHT), parent.getRelativeRect());
		setRelativeRect(new Rectangle(center.x, center.y, DIALOG_WIDTH, DIALOG_HEIGHT));
		initDialog(new Widget[]{ok});
	}
	
	public void paint(Graphics g)
	{
		GameCanvas.screen.theme.fillUIBackground(g, new Rectangle(0,0,getWidth(), getHeight()));
	}

	public void onPress(Button widget)
	{
		listener.onDialogClosed(this);
		close();
	}
}
